package cn.framelife.rainbow.ui.provider;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;

import cn.framelife.rainbow.constant.Constant;
import cn.framelife.rainbow.ui.entity.Module;
import cn.framelife.rainbow.util.DatabaseCache;
import cn.framelife.rainbow.util.FileUtil;
import cn.framelife.rainbow.util.JDBCUtil;

/**
 * 模块划分页 内容提供者
 * 
 * @author 潘广伟 p_3er@qq.com  
 * @date 2014-3-26 下午4:47:06
 */
public class ModulePageProvicer {
	
	public void loadModules(Tree moduleTree,String projectName,String selectPath){
		List<String> itemNames = FileUtil.getChildPackage(projectName,selectPath);
		for(String itemName : itemNames){
			Module module = new Module();
			module.setModuleName(itemName);
			TreeItem item = new TreeItem(moduleTree, SWT.NONE);
			item.setText(module.getModuleName());
			item.setData(module);
		}
	}
	
	public void addModuleItem(Tree moduleTree,Module module){
		TreeItem item = new TreeItem(moduleTree, SWT.NONE);
		item.setText(module.getModuleName());
		item.setData(module);
	}
	
	public void loadTables(Tree tableTree) throws Exception{
		List<String> tableNames = JDBCUtil.getTableNames();
		for(String tableName : tableNames){
			TreeItem item = new TreeItem(tableTree, SWT.NONE);
			item.setText(tableName);
		}
	}
}
